<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24"></a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('五金配件入库单')">导出</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-tabs v-model="activeKey" @change="handleChangeTab">
        <a-tab-pane key="unCreated" tab="未生成">
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="detailId"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns2"
            :dataSource="unCreatedTable.dataSource"
            :pagination="unCreatedTable.ipagination"
            :loading="unCreatedTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeysUncreated, onChange: onSelectChangeUncreated }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)"
              >下载</a-button>
            </template>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="notGenerated" tab="暂存中">
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="detailId"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="notGeneratedTable.dataSource"
            :pagination="notGeneratedTable.ipagination"
            :loading="notGeneratedTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)"
              >下载</a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical"></a-divider>
              <act-apply-btn
                v-show="record.instant < 0"
                @success="loadData"
                :data-id="record.id"
                :serviceName="serviceName"
                :variables="record"
              ></act-apply-btn>
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">
                  更多
                  <a-icon type="down" />
                </a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
        <!-- <a-tab-pane key="needEdit" tab="需修改">
          <a-table
            ref="needEditTable"
            size="middle"
            bordered
            rowKey="detailId"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="needEditTable.dataSource"
            :pagination="needEditTable.ipagination"
            :loading="needEditTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeysNeedEdit, onChange: onSelectChangeNeedEdit }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)"
              >下载</a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a v-if="record.instant < 0" @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical"></a-divider>
              <act-apply-btn
                v-show="record.instant < 0"
                @success="loadData"
                :data-id="record.id"
                :serviceName="serviceName"
                :variables="record"
              ></act-apply-btn>
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">
                  更多
                  <a-icon type="down" />
                </a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane> -->
        <a-tab-pane key="approving" tab="处理中">
          <a-table
            ref="approvingTable"
            size="middle"
            bordered
            rowKey="detailId"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="approvingTable.dataSource"
            :pagination="approvingTable.ipagination"
            :loading="approvingTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeysApproving, onChange: onSelectChangeApproving }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)"
              >下载</a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">
                  更多
                  <a-icon type="down" />
                </a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
        <a-tab-pane key="approved" tab="处理完成">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="2">
              <a-col :xl="8" :lg="11" :md="12" :sm="24">
                <a-form-item label="开始日期">
                  <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="startTime_begin"></j-date>
                  <span class="query-group-split-cust"></span>
                  <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="startTime_end"></j-date>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                </span>
              </a-col>
            </a-row>
          </a-form>
          <a-table
            ref="approvedTable"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="columns"
            :dataSource="approvedTable.dataSource"
            :pagination="approvedTable.ipagination"
            :loading="approvedTable.loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeysApproved, onChange: onSelectChangeApproved }"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="downloadFile(text)"
              >下载</a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">
                  更多
                  <a-icon type="down" />
                </a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </a-tab-pane>
      </a-tabs>
    </div>

    <!-- <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap1"
        :scroll="{x:true}"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt
            style="max-width:80px;font-size: 12px;font-style: italic;"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >下载</a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>-->

    <tsl-common-instock-bill-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TslCommonInstockBillModal from './modules/TslCommonInstockBillModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import '@/assets/less/TableExpand.less'
import moment from 'dayjs'
import { getAction, getFileAccessHttpUrl, deleteAction, postAction } from '@api/manage'
import ActApplyBtn from '@views/flowable/components/ActApplyBtn'
import ActCancelBtn from '@views/flowable/components/ActCancelBtn'
import ActHandleBtn from '@views/flowable/components/ActHandleBtn'
import ActHistoricDetailBtn from '@views/flowable/components/ActHistoricDetailBtn'
import { parseTime } from '@/utils/index.js'

export default {
  name: 'TslCommonInstockBillList',
  mixins: [JeecgListMixin],
  components: {
    TslCommonInstockBillModal,
    ActApplyBtn,
    ActCancelBtn,
    ActHandleBtn,
    ActHistoricDetailBtn,
  },
  data() {
    return {
      description: '五金配件入库单管理页面',
      moment,
      serviceName: 'tslCommonInstockBillService',
      activeKey: 'unCreated',
      startTime_begin: '',
      startTime_end: '',
      dateFormat: 'YYYY-MM-DD',
      tabIndex: 0,
      selectedRowKeysApproving: [],
      selectedRowKeysUncreated: [],
      selectionRowsApproving: [],
      selectionRowsUncreated: [],
      selectedRowKeysApproved: [],
      selectedRowsApproved: [],
      selectedRowKeysNeedEdit: [],
      selectedRowsNeedEdit: [],
      unCreatedTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 3000,
          pageSizeOptions: ['10', '20', '30', '3000', '6000', '9000'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      notGeneratedTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 3000,
          pageSizeOptions: ['10', '20', '30', '3000', '6000', '9000'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      needEditTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 3000,
          pageSizeOptions: ['10', '20', '30', '3000', '6000', '9000'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      approvingTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 3000,
          pageSizeOptions: ['10', '20', '30', '3000', '6000', '9000'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      approvedTable: {
        loading: false,
        dataSource: [],
        // 表头
        ipagination: {
          current: 1,
          pageSize: 3000,
          pageSizeOptions: ['10', '20', '30', '3000', '6000', '9000'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '入库类型',
          align: 'center',
          dataIndex: 'instockType_dictText',
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'commonInstockBillNo',
        },
        {
          title: '入库备注',
          align: 'center',
          dataIndex: 'remark',
        },

        {
          title: '仓库名称',
          align: 'center',
          dataIndex: 'instockWareno_dictText',
        },
        {
          title: '物料编号',
          align: 'center',
          dataIndex: 'materialNo',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'spec',
        },
        {
          title: '主单位',
          align: 'center',
          dataIndex: 'meUnit',
        },
        {
          title: '入库数量',
          align: 'center',
          dataIndex: 'meNum',
        },
        {
          title: '辅助单位',
          align: 'center',
          dataIndex: 'auUnit',
        },
        {
          title: '辅助数量',
          align: 'center',
          dataIndex: 'auNum',
        },
        {
          title: '上级单号',
          align: 'center',
          dataIndex: 'parentBillNo',
        },
        {
          title: '经办人',
          align: 'center',
          dataIndex: 'relativeBy',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysDepartName',
        },
        {
          title: '入库日期',
          align: 'center',
          dataIndex: 'instockDate',
          customRender: function (text) {
            return !text ? '' : parseTime(text, '{y}-{m}-{d}')
          },
        },
        {
          title: '供应商',
          align: 'center',
          dataIndex: 'supplierNo',
        },
        {
          title: '生产车间',
          align: 'center',
          dataIndex: 'workShopNo',
        },
        {
          title: '客户名称',
          align: 'center',
          dataIndex: 'customerNo',
        },
        {
          title: '批次',
          align: 'center',
          dataIndex: 'batchNo',
        },
        {
          title: '质检状态',
          align: 'center',
          dataIndex: 'batchNo1',
        },
        {
          title: '单价',
          align: 'center',
          dataIndex: 'price',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      columns2: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'billNo',
        },
        {
          title: '入库类型',
          align: 'center',
          dataIndex: 'instockTypeName',
        },
        {
          title: '仓库名称',
          align: 'center',
          dataIndex: 'warehouseName',
        },
        {
          title: '物料编号',
          align: 'center',
          dataIndex: 'materialNo',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '物料描述',
          align: 'center',
          dataIndex: 'materialDesc',
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'spec',
        },
        {
          title: '主计量',
          align: 'center',
          dataIndex: 'unit',
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'num',
        },
        {
          title: '辅助计量',
          align: 'center',
          dataIndex: 'auUnit_dictText',
        },
        {
          title: '辅助数量',
          align: 'center',
          dataIndex: 'auNum',
        },
        {
          title: '进厂日期',
          align: 'center',
          dataIndex: 'arrivalDate',
          customRender: function (text) {
            return !text ? '' : parseTime(text, '{y}-{m}-{d}')
          },
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : parseTime(text, '{y}-{m}-{d}')
          },
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createUserName',
        },
        {
          title: '供应商',
          align: 'center',
          dataIndex: 'supplierName',
        },
        {
          title: '单价',
          align: 'center',
          dataIndex: 'price',
        },
      ],
      // 表头
      // columns: [
      //   {
      //     title: '#',
      //     dataIndex: '',
      //     key: 'rowIndex',
      //     width: 60,
      //     align: 'center',
      //     customRender: function (t, r, index) {
      //       return parseInt(index) + 1
      //     },
      //   },
      //   {
      //     title: '单据编号',
      //     align: 'center',
      //     dataIndex: 'commonInstockBillNo',
      //   },
      //   {
      //     title: '入库日期',
      //     align: 'center',
      //     dataIndex: 'instockDate',
      //     customRender: function (text) {
      //       return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
      //     },
      //   },
      //   {
      //     title: '入库类型',
      //     align: 'center',
      //     dataIndex: 'instockType_dictText',
      //   },
      //   {
      //     title: '仓库编号',
      //     align: 'center',
      //     dataIndex: 'instockWareno_dictText',
      //   },
      //   {
      //     title: '上级单号',
      //     align: 'center',
      //     dataIndex: 'parentBillNo',
      //   },
      //   {
      //     title: '审批流程',
      //     align: 'center',
      //     dataIndex: 'flowType',
      //   },
      //   {
      //     title: '批次',
      //     align: 'center',
      //     dataIndex: 'batchNo',
      //   },
      //   {
      //     title: '供应商编号',
      //     align: 'center',
      //     dataIndex: 'supplierNo',
      //   },
      //   {
      //     title: '车间编号',
      //     align: 'center',
      //     dataIndex: 'workShopNo',
      //   },
      //   {
      //     title: '客户编号',
      //     align: 'center',
      //     dataIndex: 'customerNo',
      //   },
      //   {
      //     title: '备注',
      //     align: 'center',
      //     dataIndex: 'remark',
      //   },
      //   {
      //     title: '订单状态',
      //     align: 'center',
      //     dataIndex: 'instant',
      //   },
      //   {
      //     title: '经办人',
      //     align: 'center',
      //     dataIndex: 'relativeBy',
      //   },
      //   {
      //     title: '操作',
      //     dataIndex: 'action',
      //     align: 'center',
      //     fixed: 'right',
      //     width: 147,
      //     scopedSlots: { customRender: 'action' },
      //   },
      // ],
      url: {
        list: '/storage/tslCommonInstockBill/list',
        delete: '/storage/tslCommonInstockBill/delete',
        deleteBatch: '/storage/tslCommonInstockBill/deleteBatch',
        exportXlsUrl: '/storage/tslCommonInstockBill/exportXls',
        importExcelUrl: 'storage/tslCommonInstockBill/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
    this.startTime_begin = moment().subtract(7, 'days').format(this.dateFormat)
    this.startTime_end = moment().format(this.dateFormat)
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    curSelectedRowKeys: function () {
      if (this.tabIndex === 0) {
        return this.selectedRowKeysUncreated
      } else if (this.tabIndex === 1) {
        return this.selectedRowKeys
      } else if (this.tabIndex === 2) {
        return this.selectedRowKeysApproving
      } else if (this.tabIndex === 3) {
        return this.selectedRowKeysApproved
      }
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'commonInstockBillNo', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'date', value: 'instockDate', text: '入库日期' })
      fieldList.push({
        type: 'string',
        value: 'instockType',
        text: '入库类型',
        dictCode: 'instock_type,instock_type_name,instock_type_no',
      })
      fieldList.push({ type: 'string', value: 'instockWareno', text: '仓库编号', dictCode: 'erp_warehouse,name,code' })
      fieldList.push({ type: 'string', value: 'parentBillNo', text: '上级单号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'flowType', text: '审批流程', dictCode: '' })
      fieldList.push({ type: 'string', value: 'batchNo', text: '批次', dictCode: '' })
      fieldList.push({ type: 'string', value: 'supplierNo', text: '供应商编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'workShopNo', text: '车间编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'customerNo', text: '客户编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'int', value: 'instant', text: '订单状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'relativeBy', text: '经办人', dictCode: '' })
      this.superFieldList = fieldList
    },
    handleChangeTab() {
      switch (this.activeKey) {
        case 'unCreated':
          this.loadUnCreatedData()
          break
        case 'notGenerated':
          this.loadNotGeneratedData()
          break
        case 'needEdit':
          this.loadNeedEditData()
          break
        case 'approving':
          this.loadApprovingData()
          break
        case 'approved':
          this.loadApprovedData()
          break
        default:
          break
      }
    },
    loadUnCreatedData() {
      //未生成 找请购单审批完成的
      this.tabIndex = 0
      this.queryParam.instant = 999
      this.queryParam.openState = 'Y'
      this.unCreatedTable.loading = true
      let myurl = '/procurement/sparePartPurchaseBill/list'
      getAction(myurl, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.unCreatedTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.unCreatedTable.loading = false
        })
    },
    loadNotGeneratedData() {
      //暂存中，status=-2
      this.tabIndex = 1
      this.queryParam.instant = -2
      this.queryParam.openState = ''
      this.notGeneratedTable.loading = true
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.notGeneratedTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.notGeneratedTable.loading = false
        })
    },
    //需修改
    loadNeedEditData() {
      //需修改单据，status=-1
      this.tabIndex = 2
      this.queryParam.instant = -1
      this.needEditTable.loading = true
      this.queryParam.openState = ''
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.needEditTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.needEditTable.ipagination.total = res.result.total
            } else {
              this.needEditTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.needEditTable.loading = false
        })
    },
    //处理中
    loadApprovingData() {
      //审核中单据，status=0
      this.tabIndex = 3
      this.queryParam.instant = 1001
      this.approvingTable.loading = true
      this.queryParam.openState = ''
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.approvingTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.approvingTable.ipagination.total = res.result.total
            } else {
              this.approvingTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.approvingTable.loading = false
        })
    },
    //已审批
    loadApprovedData() {
      //已审核单据，status=999
      this.tabIndex = 4
      this.queryParam.openState = ''
      let para = {
        ...this.queryParam,
        instant: 1999,
        createTimeBg: this.startTime_begin + ' 00:00:00',
        createTimeEd: this.startTime_end + ' 23:59:59',
      }
      this.approvedTable.loading = true
      getAction(this.url.list, para)
        .then((res) => {
          if (res.success) {
            this.approvedTable.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.approvedTable.ipagination.total = res.result.total
            } else {
              this.approvedTable.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.approvedTable.loading = false
        })
    },
    async loadData() {
      //分别根据单据状态查询结果并将其放在
      this.queryParam = this.getQueryParams()
      this.loadUnCreatedData()
    },
    onSelectChangeUncreated(selectedRowKeys, selectionRows) {
      this.selectedRowKeysUncreated = selectedRowKeys
      this.selectionRowsUncreated = selectionRows
    },
    onSelectChangeApproving(selectedRowKeys, selectionRows) {
      this.selectedRowKeysApproving = selectedRowKeys
      this.selectionRowsApproving = selectionRows
    },
    onSelectChangeApproved(selectedRowKeys, selectionRows) {
      this.selectedRowKeysApproved = selectedRowKeys
      this.selectedRowsApproved = selectionRows
    },
    onSelectChangeNeedEdit(selectedRowKeys, selectionRows) {
      this.selectedRowKeysNeedEdit = selectedRowKeys
      this.selectedRowsNeedEdit = selectionRows
    },
    handleAdd: function () {
      if (this.tabIndex === 0) {
        if (this.selectionRowsUncreated.length <= 0) {
          this.$message.warning('请选择五金配件采购订单')
          return
        }
        this.$store.dispatch('saveSelectSparePurchaseBillDetail', this.selectionRowsUncreated)
        this.$store.dispatch('saveIsFromPurchase', true)
      } else if (this.tabIndex != 1) {
        this.$message.warning('只有未生成状态可以添加采购订单')
        return
      } else {
        this.$store.dispatch('saveIsFromPurchase', false)
      }

      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    handleDelete: function (id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      deleteAction(that.url.delete, { id: id }).then((res) => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message)
          that.loadNotGeneratedData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    modalFormOk() {
      //刷新后 选中的记录清除
      this.$store.dispatch('saveSelectSparePurchaseBillDetail', [])
      // 新增/修改 成功时，重载列表
      this.loadNotGeneratedData()
      //清空列表选中
      this.onClearSelected()
    },
    searchQuery() {
      this.loadApprovedData()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>